<template>
  <div class="long-comment">
		<div class="long-comment-count vux-1px-b" v-show="comments.length !== 0">{{comments.length}}条长评论</div>
    <ul class="comment-list">
      <i class="icon iconfont icon-shafa"></i>
      <li class="comment-item vux-1px-b" v-for="item in comments">
        <img class="avatar" v-lazy="item.avatar">
        <div class="comment-content">
          <span class="author">{{item.author}}</span>
          <i class="icon iconfont icon-dianzan">{{item.likes}}</i>
          <p class="text">{{item.content}}</p>
          <template v-if="item.reply_to!==undefined">
            <p class="reply">
              <span class="reply-author">//{{item.reply_to.author}}:</span>
              {{item.reply_to.content}}
            </p>
          </template>
          <span class="date">{{changeTime(item.time)}}</span>
        </div>
      </li>
    </ul>
	</div>
</template>
<script>
import axios from "axios";
import moment from "moment";
export default {
  props: ["id"],
  data() {
    return {
      comments: []
    }
  },
  created() {
		this.getData();
  },
  mounted() {
  },
  methods: {
    // 没有长评显示沙发， “深度长评虚位以待”
    // 获取长评论数据
    getData() {
      axios
        .get("api/story/" + this.id + "/long-comments")
        .then(response => {
          this.comments = response.data.comments;
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 转换时间戳
    changeTime(time) {
      return moment(time).format('MM-DD HH:mm');
    }
  }
};
</script>
<style lang="less" scoped>
.long-comment {
  .long-comment-count {
    font-size: 16px;
    color: #333;
    padding: 9px 20px;
    line-height: 1.5em;
    font-weight: 700;
    margin: 0;
  }
  .comment-list {
    padding: 0;
    margin-bottom: 0;
    .icon-shafa {
      position: absolute;
      left: 50%;
      top: 40%;
      margin-left: -90px;
      margin-top: -90px;
      color: #e4e4e4;
      display: none;
    }
    .comment-item {
      display: flex;
      font-size: 15px;
      color: #666;
      padding: 20px;
      .avatar {
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
        border-radius: 50%;
      }
      .comment-content {
        flex: 1;
        padding-left: 10px;
        .author {
          font-size: 19px;
          color: #000;
          font-weight: 400;
        }
        .icon-dianzan {
          float: right;
          color: #b4b4b4;
        }
        .text {
          margin: 10px 0;
          line-height: 18px;
        }
        .reply {
          margin: 10px 0;
          color: #929292;
          line-height: 18px;
          .reply-author {
            color: #000;
          }
        }
        .hideReply {
          overflow: none;
        }
        .date {
          color: #ccc;
        }
        .expand {
          display: block;
          float: right;
          width: 45px;
          height: 20px;
          text-align: center;
          line-height: 20px;
          background: #d8e4f2;
        }
      }
    }
  }
}
</style>
